package com.biye.api.service.impl;

import com.alibaba.fastjson.JSONObject;
import com.base.common.edu.entity.Staff;
import com.base.common.edu.mapper.StaffMapper;
import com.base.common.httpStatusCode.enumDefine.StatusCode;
import com.biye.api.service.TeacherService;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import javax.annotation.Resource;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

@Service
@Transactional
public class TeacherServiceImpl implements TeacherService {

    @Resource
    private StaffMapper staffMapper;

    @Override
    public JSONObject queryAllTeacherDropDownList() {
        JSONObject json = new JSONObject();
        String msg = "暂无数据";
        int statusCode = StatusCode.Failure._statusCode;
        List<Staff> staff = staffMapper.queryStaff(new Staff());
        if ( staff.size() > 0 ){
            List<Map<String, String>> list_t = new ArrayList<>();
            Map<String, String> temp_map = null;
            for ( Staff sta : staff ) {
                temp_map = new HashMap<>();
                temp_map.put("label", sta.getName() + "-" + sta.getTno());
                temp_map.put("value", sta.getTno());
                list_t.add(temp_map);
            }
            json.put("list", list_t);
            msg = "查询成功";
            statusCode = StatusCode.Success._statusCode;
        }
        json.put("statusCode", statusCode);
        json.put("msg", msg);
        return json;
    }

    @Override
    public JSONObject queryAllTeacherDropDownList2() {
        JSONObject json = new JSONObject();
        String msg = "暂无数据";
        int statusCode = StatusCode.Failure._statusCode;
        List<Staff> staff = staffMapper.queryStaff(new Staff());
        if ( staff.size() > 0 ){
            List<Map<String, String>> list_t = new ArrayList<>();
            Map<String, String> temp_map = null;
            for ( Staff sta : staff ) {
                temp_map = new HashMap<>();
                temp_map.put("label", sta.getName() + "-" + sta.getTno());
                temp_map.put("value", sta.getStaffId());
                list_t.add(temp_map);
            }
            json.put("list", list_t);
            msg = "查询成功";
            statusCode = StatusCode.Success._statusCode;
        }
        json.put("statusCode", statusCode);
        json.put("msg", msg);
        return json;
    }
}
